const fs = require('fs');
const path = require('path');
const hiSmartLiteEx = require('../hiSmartLiteEx');

class ConfigReader {
  getMenuConfig() {
    const menuPath = hiSmartLiteEx.language === 'en' ? 'menu.en.json' : 'menu.zh-cn.json';
    const configPath = path.join(hiSmartLiteEx.extensionPath, 'media', 'json', 'menu', menuPath);
    const data = fs.readFileSync(configPath);
    const dataStr = data.toString();
    let menuList = Object.assign(JSON.parse(dataStr));
    return menuList;
  }

  getMenuSectionById(sectionId) {
    const menuList = this.getMenuConfig();
    for (const menuObj of menuList.menu) {
      if (menuObj.sectionId === sectionId) {
        return menuObj.menuItemList;
      }
    }
    return [];
  }
}
module.exports = ConfigReader;